#pragma once
#include <vector>
#include <any>
#include <algorithm>
#include "CObserver.h"

class CSubject {
public:
    void attach(CObserver* observer) { m_observers.push_back(observer); }
    
    void detach(CObserver* observer) {
        m_observers.erase(std::remove(m_observers.begin(), m_observers.end(), observer), m_observers.end());
    }
    
    void notify(const std::any& value = INT_MAX) {
        for (auto* observer : m_observers)
            observer->update(value);
    }

    virtual ~CSubject() = default;

private:
    std::vector<CObserver*> m_observers;
};